package 多线程.复习.线程方法;

//通过内置的属性中断线程
public class ThreadInterrupted {
    private static class MyRunnable implements Runnable{
        @Override
        public void run() {
            while (true){
                System.out.println("渣渣正在通话中。。。");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("渣渣是否被中断 :" +Thread.currentThread().isInterrupted());
                    System.err.println("那个狗日剪我电话线");
//                    break;
                }
            }
//            System.out.println("渣渣被迫挂了电话。。。。");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable,"渣渣");
        thread.start();
        System.out.println("主线程安全");
        Thread.sleep(2000);
//        System.out.println("警报！！！有人在剪电话线。。");
        thread.interrupt();
        System.out.println("电话线断了。。。");
    }
}
